You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
933 B
37 lines
933 B
import type { RequestHandler } from "@sveltejs/kit";
|
|
|
|
export const get: RequestHandler = async({ request, url, params, locals }) => {
|
|
const proxyUrl = `${import.meta.env.VITE_STUFFLOG3_API}/api/${params.any}${url.search}`;
|
|
|
|
const headers = {};
|
|
if (locals.idToken != null) {
|
|
headers["Authorization"] = `Bearer ${locals.idToken}`;
|
|
} else if (request.headers.get("authorization") != null) {
|
|
headers["Authorization"] = request.headers.get("authorization");
|
|
}
|
|
|
|
const res = await fetch(proxyUrl, {
|
|
method: request.method,
|
|
headers: headers,
|
|
body: request.body,
|
|
}).catch(err => {
|
|
console.warn(err);
|
|
throw err;
|
|
});
|
|
|
|
const result = {
|
|
status: res.status,
|
|
body: await res.text(),
|
|
headers: {},
|
|
}
|
|
res.headers.forEach((v, k) => {
|
|
result.headers[k] = v;
|
|
})
|
|
|
|
return result;
|
|
}
|
|
|
|
export const options = get;
|
|
export const post = get;
|
|
export const put = get;
|
|
export const del = get;
|